package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.FlightInformation;
import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.service.FlightServie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Flights")
public class FlightController {
    @Autowired
    private FlightServie flightServie;

    /**
     * 查询所有航班
     * @return
     */
    @GetMapping
    public Result list(){
        log.info("查询所有航班");
        List<FlightInformation> flightInformationList = flightServie.list();
        return Result.success(flightInformationList);
    }

    /**
     * 根据id删除指定航班
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteFlight(@PathVariable Integer id){
        log.info("根据id{}删除指定航班",id);
        flightServie.deleteFlight(id);
        return Result.success();
    }

    /**
     * 增加航班
     * @param flightInformation
     * @return
     */
    @PostMapping
    public Result addFlight(@RequestBody FlightInformation flightInformation){
        log.info("增加航班");
        flightServie.addFlight(flightInformation);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getFlightById(@PathVariable Integer id){
        log.info("获取指定id{}的航班",id);
        FlightInformation flightInformation = flightServie.getFlightById(id);
        return Result.success(flightInformation);
    }

    @PutMapping
    public Result updateFlight(@RequestBody FlightInformation flightInformation){
        log.info("更新id为{}的航班",flightInformation.getID());
        flightServie.updateFlight(flightInformation);
        return Result.success();
    }

    /**
     * 查询指定出发地与目的地的航班
     * @return
     */
    @GetMapping("/getFlightByCFCityAndDDCity")
    public Result getFlightByCFCityAndDDCity(@RequestParam String CFCity,@RequestParam String DDCity){
        log.info("查询指定出发地与目的地的航班");
        List<FlightInformation> flightInformationList = flightServie.getFlightByCFCityAndDDCity(CFCity,DDCity);
        return Result.success(flightInformationList);
    }
}
